﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using VNet.VisiSuite.Common.Resource;

namespace VNet.VisiSuite.VisiAdmin.Models
{
    public class LaunchApplicationModel : ComparableBaseModel<LaunchApplicationModel>, IDataErrorInfo
    {
        private int _launchApplicationId;
        public int LaunchApplicationId
        {
            get { return _launchApplicationId; }
            set
            {
                _launchApplicationId = value;
                OnPropertyChanged("LaunchApplicationId");
            }
        }

        private int _areaId;
        public int AreaId
        {
            get { return _areaId; }
            set
            {
                _areaId = value;
                OnPropertyChanged("AreaId");
            }
        }

        private string _description;
        [Category("Properties")]
        [DisplayName("Description")]
        [Description("Launch Application Description.")]
        [DefaultValue("")]
        public string Description
        {
            get { return _description; }
            set
            {
                _description = value;
                OnPropertyChanged("Description", true);
            }
        }

        private string _application;
        [Category("Properties")]
        [DisplayName("Application")]
        [Description("Launch Application.")]
        [DefaultValue("")]
        public string Application
        {
            get { return _application; }
            set
            {
                _application = value;
                OnPropertyChanged("Application", true);
            }
        }

        private string _arguments;
        [Category("Properties")]
        [DisplayName("Arguments")]
        [Description("Launch Application Arguments.")]
        [DefaultValue("")]
        public string Arguments
        {
            get { return _arguments; }
            set
            {
                _arguments = value;
                OnPropertyChanged("Arguments", true);
            }
        }

        private int _sortOrder;
        public int SortOrder
        {
            get { return _sortOrder; }
            set
            {
                _sortOrder = value;
                OnPropertyChanged("SortOrder");
            }
        }

        private bool _enabled;
        [Category("Properties")]
        [DisplayName("Enabled")]
        [Description("Enable / disable the Launch Application.")]
        public bool Enabled
        {
            get { return _enabled; }
            set
            {
                _enabled = value;
                OnPropertyChanged("Enabled", true);
            }
        }

        private string _createdBy;
        [Category("Update History")]
        [DisplayName("Created By")]
        [Description("User who created the launch application in VisiAdmin.")]
        public string CreatedBy
        {
            get { return _createdBy; }
            set
            {
                _createdBy = value;
                OnPropertyChanged("CreatedBy");
            }
        }

        private string _createdDate;
        [Category("Update History")]
        [DisplayName("Created On")]
        [Description("Date when the launch application was created in VisiAdmin.")]
        public string CreatedDate
        {
            get { return _createdDate; }
            set
            {
                _createdDate = value;
                OnPropertyChanged("CreatedDate");
            }
        }

        private string _lastUpdatedBy;
        [Category("Update History")]
        [DisplayName("Updated By")]
        [Description("User who last edited the launch application in VisiAdmin.")]
        public string LastUpdatedBy
        {
            get { return _lastUpdatedBy; }
            set
            {
                _lastUpdatedBy = value;
                OnPropertyChanged("LastUpdatedBy");
            }
        }

        private string _lastUpdatedDate;
        [Category("Update History")]
        [DisplayName("Updated On")]
        [Description("Date when the launch application was last edited in VisiAdmin.")]
        public string LastUpdatedDate
        {
            get { return _lastUpdatedDate; }
            set
            {
                _lastUpdatedDate = value;
                OnPropertyChanged("LastUpdatedDate");
            }
        }

        #region IDataErrorInfo Implementation

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get
            {
                if (!ShouldValidate)
                    return string.Empty;

                if (columnName == "Description" && string.IsNullOrWhiteSpace(Description))
                    return ValidationMessages.DescriptionRequired;
                else if (columnName == "Application" && string.IsNullOrWhiteSpace(Application))
                    return ValidationMessages.ApplicationRequired;
                return string.Empty; ;
            }
        }

        #endregion

        #region Override Equals methods
        public bool Equals(LaunchApplicationModel other)
        {
            if (ReferenceEquals(null, other))
                return false;
            if (ReferenceEquals(this, other))
                return true;
            return string.Equals(Description, other.Description)
                && string.Equals(Application, other.Application)
                && string.Equals(Arguments, other.Arguments)
                && Enabled == other.Enabled;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;
            if (obj.GetType() != this.GetType())
                return false;
            return Equals((LaunchApplicationModel)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var result = 0;
                result = (result * 397) ^ (Description ?? string.Empty).GetHashCode();
                result = (result * 397) ^ (Application ?? string.Empty).GetHashCode();
                result = (result * 397) ^ (Arguments ?? string.Empty).GetHashCode();
                result = (result * 397) ^ Enabled.GetHashCode();
                return result;
            }
        }
        #endregion
    }
}
